package com.xsw.edu.web.test;

import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

/**
 * Created by lenovo on 2019/7/13.
 */
public class Demo {

    @Test
    public void test01(){
        //1.创建数据库源
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/edu1?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false");
        dataSource.setUsername("root");
        dataSource.setPassword("000000");

        //2.创建模板
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        String sql = "SELECT * FROM t_user";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        for (int i=0; i < list.size(); i++){
            System.out.println(list.get(i));
        }
        //System.out.println(list);
    }
}
